package com.jian.android.autojipai.ui.page.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.core.internal.view.SupportMenu;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.jian.android.autojipai.R;
import com.jian.android.autojipai.data.bean.Poker;

import java.util.List;

public class AutoPokerRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<Poker> allList;

    public AutoPokerRvAdapter(List<Poker> list) {
        this.allList = list;
    }

    @Override
    public int getItemCount() {
        List<Poker> list = this.allList;
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_auto_poker, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        ViewHolder viewHolder2 = (ViewHolder) viewHolder;
        Poker poker = this.allList.get(i);
        viewHolder2.tvParValue.setText(poker.getParValue());
        viewHolder2.tvNumber.setText(String.valueOf(poker.getNumber()));
        if (poker.getCount() == poker.getNumber()) {
            viewHolder2.tvNumber.setTextColor(SupportMenu.CATEGORY_MASK);
        } else {
            viewHolder2.tvNumber.setTextColor(ViewCompat.MEASURED_STATE_MASK);
        }
        if (poker.isHaveNumber()) {
            viewHolder2.itemView.setVisibility(View.VISIBLE);
        } else {
            viewHolder2.itemView.setVisibility(View.INVISIBLE);
        }
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private final TextView tvNumber;
        private final TextView tvParValue;

        public ViewHolder(View view) {
            super(view);
            this.tvParValue = (TextView) view.findViewById(R.id.tv_value);
            this.tvNumber = (TextView) view.findViewById(R.id.tv_number);
        }
    }
}
